package com.efast.dmom.mes.datahandlers.entity;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.dmom.mes.bean.QualityDefectCode;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.dao.entity.QualityDefectDao;
import com.efast.dmom.mes.datahandlers.base.QualityBaseDataHandler;
import com.efast.dmom.mes.entity.QualityDefectEntity;
import com.efast.dmom.mes.util.SpringWebUtils;
import com.efast.dmom.mes.util.TimeUtil;
@Component
public class QualityDefectHandler extends QualityBaseDataHandler<QualityDefectCode>{
	
	@Autowired
	private QualityDefectDao qualityDefectDao;
	
	
	@Override
	public ResultBean save(QualityDefectCode obj) {
		ResultBean resultBean = new ResultBean();
		obj.getInnerData().setSiteId(DataHandlerUtils.getSiteId());
		obj.getInnerData().setCreationTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setCreationTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setCreator(SpringWebUtils.getRequestUser());
		obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//	    obj.getInnerData().setCreationPid(DataHandlerUtils.getDmomPid());
//	    obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
		obj.getInnerData().setRowStatus(1);
		obj.getInnerData().setRowTrxId(1);
		qualityDefectDao.save(obj.getInnerData());
		return resultBean;
	}
	@Override
	public ResultBean update(QualityDefectCode obj) {
		ResultBean resultBean = new ResultBean();
		
		obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//	    obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
		obj.getInnerData().setRowTrxId(1);
		qualityDefectDao.update(obj.getInnerData());
		return resultBean;
	}
	@Override
	public void batchDeleteById(List<QualityDefectCode> objs) {
		List<QualityDefectEntity> list = new ArrayList<QualityDefectEntity>();
			for (QualityDefectCode obj : objs) {
				obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
				obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
				obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//			    obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
				obj.getInnerData().setRowTrxId(1);
				list.add(obj.getInnerData());
			}
		qualityDefectDao.deleteBatch(list);
	}
	@Override
	public QualityDefectCode getById(long id) {
		 QualityDefectCode qualityDefectCode = new QualityDefectCode();
		 qualityDefectCode.setInnerData(qualityDefectDao.getById(id));
		return qualityDefectCode;
	}
	@Override
	public QualityDefectCode getByName(String name) {
		 QualityDefectCode qualityDefectCode = new QualityDefectCode();
		 qualityDefectCode.setInnerData(qualityDefectDao.getByName(name));
		return qualityDefectCode;
	}

	public QualityDefectCode getByPartGroupCode(String partGroupCode) {
		QualityDefectCode qualityDefectCode = new QualityDefectCode();
		qualityDefectCode.setInnerData(qualityDefectDao.getByCode(partGroupCode));
		return qualityDefectCode;
	}

	

	@Override
	public QualityDefectCode getByCode(String code) {
		 QualityDefectCode qualityDefectCode = new QualityDefectCode();
		 qualityDefectCode.setInnerData(qualityDefectDao.getByCode(code));
		return qualityDefectCode;
	}

	@Override
	public ResultBean saveBatch(List<QualityDefectCode> obj) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean updateBatch(List<QualityDefectCode> obj) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean deleteBatch(List<QualityDefectCode> obj) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public ResultBean delete(QualityDefectCode obj) {
		// TODO Auto-generated method stub
		return null;
	}




}
